package com.ruoyi.system.utils;

import java.time.Instant;

/**
 * @author xy
 * @version 1.0
 * @description:
 * @date 2024/7/6 17:26
 */
public class MyMath {

    private final static float lowPrice = 0.56F;
    private final static float midPrice = 0.61F;
    private final static float highPrice = 0.86F;

    /**
     * 计算电费
     *
     * @param lastUsage
     * @param nowUsage
     * @return
     */
    public static float getPayAmount(int lastUsage, int nowUsage) {
        int delUsage = nowUsage - lastUsage;
        float result = 0;
        if (delUsage <= 180) {
            return delUsage * lowPrice;
        } else if (delUsage <= 260) {
            return 180 * lowPrice + (delUsage - 180) * midPrice;
        } else {
            return 180 * lowPrice + 80 * midPrice + (delUsage - 260) * highPrice;
        }
    }

    /**
     * 生成一个随机且唯一的长ID
     * @return
     */
    public static Long generatePkId(){
        Long timestamp = Instant.now().toEpochMilli();
        Long randomNumber = (long) (Math.random()*1000);
        return Long.parseLong(String.valueOf(timestamp) + String.valueOf(randomNumber));
    }
}
